package com.admin.business.portalWebsite.venusPortalQuestionType;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 问答类型表
 * @create: 2023-11-20 18:20:03
 **/
@Service("venusPortalQuestionTypeService")
@Slf4j
public class VenusPortalQuestionTypeService{

    @Resource
    VenusPortalQuestionTypeDao venusPortalQuestionTypeDao;

    /**
     * 添加问答类型表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - type_name:问题类型名称
     *                   - type_num:点击量
     *                   - begin_time:创建时间
     *                   - update_time:更新时间
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return addVenusPortalQuestionType(CDO cdoRequest) {
        venusPortalQuestionTypeDao.addVenusPortalQuestionType(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新问答类型表数据
     *
     * @param cdoRequest - id:主键
     *                   - type_name:问题类型名称
     *                   - type_num:点击量
     *                   - begin_time:创建时间
     *                   - update_time:更新时间
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return updateVenusPortalQuestionTypeById(CDO cdoRequest) {
        venusPortalQuestionTypeDao.updateVenusPortalQuestionTypeById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除问答类型表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return deleteVenusPortalQuestionTypeById(CDO cdoRequest){
        int count = venusPortalQuestionTypeDao.deleteVenusPortalQuestionTypeById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除问答类型表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return deleteVenusPortalQuestionType(CDO cdoRequest) {
        int count = venusPortalQuestionTypeDao.deleteVenusPortalQuestionType(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取问答类型表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return getVenusPortalQuestionTypeById(CDO cdoRequest) {
        CDO cdoMapperResult = venusPortalQuestionTypeDao.getVenusPortalQuestionTypeById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取问答类型表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return getVenusPortalQuestionTypeListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusPortalQuestionTypeDao.getVenusPortalQuestionTypeListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusPortalQuestionTypeDao.getVenusPortalQuestionTypeCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取问答类型表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-20 18:20:03
     */
    @OpenApi
    public Return getVenusPortalQuestionTypeListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusPortalQuestionTypeDao.getVenusPortalQuestionTypeListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusPortalQuestionTypeDao.getVenusPortalQuestionTypeCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
